package io.github.wjehovah.yyn.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;

import io.github.wjehovah.yyn.App;
import io.github.wjehovah.yyn.R;
import io.github.wjehovah.yyn.bean.ImgDataBean;
import io.github.wjehovah.yyn.bean.ImgDataBean.ImgDetail;

/**
 * Created by wuyong on 15/8/5.图片的Adapter
 */
public class ImgAdapter extends BaseAdapter {
    private final ImgDataBean data;
    private LayoutInflater mLayoutInflater;

    public ImgAdapter(ImgDataBean data, Context context) {
        this.data = data;
        mLayoutInflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return data.list.size();
    }

    @Override
    public ImgDetail getItem(int position) {
        return data.list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.image_item, null, false);
            holder.usericon = (ImageView) convertView.findViewById(R.id.iv_top_item_usericon);//用户头像
            holder.username = (TextView) convertView.findViewById(R.id.tv_top_item_username);//用户名
            holder.passtime = (TextView) convertView.findViewById(R.id.tv_top_item_passtime);//审核通过时间
            holder.content = (TextView) convertView.findViewById(R.id.tv_content);//内容
            holder.contentImg = (ImageView) convertView.findViewById(R.id.iv_content);//内容图片


            holder.love = (TextView) convertView.findViewById(R.id.tv_foot_love);//顶
            holder.hate = (TextView) convertView.findViewById(R.id.tv_foot_hate);//踩
            holder.transmit = (TextView) convertView.findViewById(R.id.tv_foot_transmit);//分享
            holder.comment = (TextView) convertView.findViewById(R.id.tv_foot_commnet);//评论
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ImgDetail imgDetail = getItem(position);
        BitmapUtils bitmapUtils = new BitmapUtils(App.getContext(), "", 0.4f, 1024 * 1024 * 6);
        bitmapUtils.display(holder.usericon, imgDetail.profile_image);//用户名头像；

        holder.username.setText(imgDetail.screen_name);//用户名
        holder.passtime.setText(imgDetail.created_at);//时间
        holder.content.setText(imgDetail.text);//内容
        bitmapUtils.display(holder.contentImg, imgDetail.image1);//内容图片；
        holder.love.setText(imgDetail.love);//顶
        holder.hate.setText(imgDetail.hate);//踩
        holder.transmit.setText(imgDetail.repost);//分享
        holder.comment.setText(imgDetail.comment);//评论

        return convertView;
    }

    static class ViewHolder {
        ImageView usericon;
        TextView username;
        TextView passtime;
        TextView content;
        TextView love;
        TextView hate;
        TextView transmit;
        TextView comment;
        ImageView contentImg;
    }
}
